<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>几何体</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <script type="module">
        import * as THREE from 'three'
        import { OrbitControls } from "three/examples/jsm/controls/OrbitControls"
        const scene = new THREE.Scene()
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000)
        const renderer = new THREE.WebGLRenderer()
        renderer.setSize(window.innerWidth, window.innerHeight)
        document.body.appendChild(renderer.domElement)
        camera.position.set(0, 0, 10)

        //光线
        const ambientLight = new THREE.AmbientLight(0x404040)
        const directionLight = new THREE.DirectionalLight(0xffffff, 0.5)
        directionLight.position.set(3, 3, 3,)
        scene.add(ambientLight, directionLight)

        //创建几何体
        const geometry = new THREE.SphereGeometry(2, 30, 30)
        //设置材质
        const material = new THREE.MeshStandardMaterial({
            color: 0xff000,
            roughness: 0.5,
            metalness: 0.5
            // emissive: 0xfff00,
        })
        //组合成物体
        const cube = new THREE.Mesh(geometry, material)
        scene.add(cube)


        const controls = new OrbitControls(camera, renderer.domElement)
        controls.enableDamping = true //阻尼感 运动惯性
        function animate() {
            requestAnimationFrame(animate)
            controls.update()
            renderer.render(scene, camera)
        }
        animate()
    </script>
</body>

</html>